import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.JLabel;
import javax.swing.JPanel;


public class MainScene extends JPanel implements Runnable{

	Point pt = new Point();
	boolean keyPressed = false;
	Point target = new Point();
	Point shootedPoint = new Point();
	Point ovalPoint = new Point();
	double degree;
	int dx, dy ;
	
	Thread mainThread;
	GameManager gameManager;
	static JLabel debugText;
	
	public MainScene()
	{
		gameManager = new GameManager(); 
		//enemy = new Enemy( MainFrame.WINDOW_SIZE_X - 100 , MainFrame.WINDOW_SIZE_Y - 200);
		
		debugText =new JLabel();
		debugText.setLocation(20,20);
		debugText.setSize(300 , 50);
		debugText.setText("왜 가운데 나옴묘?");
		this.add(debugText);
		
		this.addMouseMotionListener(new MouseMotionListener() {
			
			@Override
			public void mouseMoved(MouseEvent e) {
			}
			
			@Override
			public void mouseDragged(MouseEvent e) {
				
			}
		});
		this.addMouseListener(
			new MouseListener() 
			{
			
				@Override
				public void mouseReleased(MouseEvent e) {
					// TODO Auto-generated method stub
				}
				
				@Override
				public void mousePressed(MouseEvent e) {
					// TODO Auto-generated method stub
					
				}
				@Override
				public void mouseExited(MouseEvent e) {
					// TODO Auto-generated method stub
				}
				@Override
				public void mouseEntered(MouseEvent e) {
					// TODO Auto-generated method stub
				}
				@Override
				public void mouseClicked(MouseEvent e) {
					// TODO Auto-generated method stub
					
				}
			}
		);
		
		this.addKeyListener(new KeyAdapter() {
			
			@Override
			public void keyPressed(KeyEvent e) {
				super.keyPressed(e);
				gameManager.keyPressed(e);
			}
			
			@Override
			public void keyReleased(KeyEvent e) {
				super.keyReleased(e);
				gameManager.keyReleased(e);
			}
			
		});
		
		mainThread = new Thread(this);
		mainThread.start();
	}
	
	public void update()
	{
		gameManager.update();
		
		
		//enemy.update();
	}
	public void paint(Graphics g) {
		super.paint(g);
		gameManager.render(g);
		
		//enemy.render(g);
	}
	
	@Override
	public void addNotify() {
		super.addNotify();
	}

	@Override
	public void run() {
		long  lastUpdateTime = 0;
		while ( true )
		{
			
			long currentTime = System.currentTimeMillis();
			if (lastUpdateTime + 30 < currentTime) {
				//1. update (데이터 변경)
				update();
	
				//2. drawing (화면 출력)
				repaint();//update() -> paint(); : UI 쓰레드에서 처리
				lastUpdateTime = currentTime;
			}
		}
	}
}
